GetTaskByIdQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
dl 0
loc 15
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 8 2
1
import { Inject } from '@nestjs/common';
2
import { QueryHandler } from '@nestjs/cqrs';
3
import { ITaskRepository } from 'src/Domain/Task/Repository/ITaskRepository';
4
import { TaskView } from '../View/TaskView';
5
import { GetTaskByIdQuery } from './GetTaskByIdQuery';
6
import { TaskNotFoundException } from 'src/Domain/Task/Exception/TaskNotFoundException';
7
8
@QueryHandler(GetTaskByIdQuery)
9
export class GetTaskByIdQueryHandler {
10
  constructor(
11
    @Inject('ITaskRepository')
12
    private readonly taskRepository: ITaskRepository
13
  ) {}
14
15
  public async execute(query: GetTaskByIdQuery): Promise<TaskView> {
16
    const task = await this.taskRepository.findOneById(query.id);
17
    if (!task) {
18
      throw new TaskNotFoundException();
19
    }
20
21
    return new TaskView(task.getId(), task.getName());
22
  }
23
}
24